package com.smz.controller;


import com.smz.entity.TDp;
import com.smz.service.TDpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
public class TDpController {


    @Autowired
    private TDpService tDpService;



    @ApiOperation("查找全部子部门")
    @GetMapping("/tdps")
    public ResponseEntity<List<TDp>>findAllTDps(){
        List<TDp> tDps=tDpService.list();
        return ResponseEntity.ok(tDps);
    }

    @ApiOperation("增加子部门")
    @PostMapping("/tdp")
    public ResponseEntity<String>addTStaff(@RequestBody TDp tDp){
        tDpService.save(tDp);
        return  ResponseEntity.ok("ok");
    }
    @ApiOperation("删除子部门")
    @DeleteMapping("/tdp/{id}")
    public  ResponseEntity<String>deleteTStaff(@PathVariable("id")Integer id){
        tDpService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("通过id部门")
    @GetMapping("/tdp/{id}")
    public ResponseEntity<TDp> findById(@PathVariable("id")Integer id){
        TDp tDp = tDpService.findTdpById(id);
        return ResponseEntity.ok(tDp);
    }

    @ApiOperation("通过id查询所有")
    @GetMapping("/tdps/{id}")
    public ResponseEntity<List<TDp>> findAllTDpsById(@PathVariable("id")Integer id){
        List<TDp> all =tDpService.findAllTDpById(id) ;
        return ResponseEntity.ok(all);
    }


}
